package com.leetcode.support;

import java.util.Arrays;
import java.util.OptionalDouble;

public class ArraysRecord {

    public static void main(String[] arg0) {
        int[] arr1 = {1, 5, 3, 6, 7};
        int sum = Arrays.stream(arr1).sum(); // 求和
        OptionalDouble avg = Arrays.stream(arr1).average(); // 求平均值
        double average = avg.getAsDouble();
        int min = Arrays.stream(arr1).min().getAsInt(); // 最小值
        int max = Arrays.stream(arr1).max().getAsInt(); // 最大值
        System.out.println("arr1 和 = " + sum + ", 平均值 = " + average
                + ", 最小值 = " + min + ", 最大值 = " + max);

        int[] arr2 = {1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4};
        arr2 = Arrays.stream(arr2).sorted().distinct().toArray();
        System.out.println("arr2排序去重 = " + Arrays.toString(arr2));

        int t = Integer.bitCount(arr1[4]); // 整数 s 转化成二进制表示时，1的个数
    }

}
